#include "CompStrat.h"

using namespace BWAPI;
using namespace std;

CompStrat::CompStrat(void)
{
}

CompStrat::~CompStrat(void)
{
}

//Does any special work for a strategy subclass
void CompStrat::setTargetsSpecial(){
	targetPriority = targets;
	by_range functor;
	sort(targetPriority.begin(), targetPriority.end(), functor);
}

//Get a target for a given unit.
vector<string> & CompStrat::getTargetPriority(string){

	return targetPriority;
}


bool CompStrat::by_range::operator()(string const &a, string const &b) { 
	UnitType aType = BWAPI::UnitTypes::getUnitType(a);
	UnitType bType = BWAPI::UnitTypes::getUnitType(b);
	WeaponType aWeapon = aType.groundWeapon();
	if(aWeapon.getName() == WeaponTypes::None.getName()){
		aWeapon = aType.groundWeapon();
		if(aWeapon.getName() == WeaponTypes::None.getName()){
			return false;
		}
	}
	WeaponType bWeapon = bType.groundWeapon();
	if(bWeapon.getName() == WeaponTypes::None.getName()){
		bWeapon = bType.groundWeapon();
		if(bWeapon.getName() == WeaponTypes::None.getName()){
			return true;
		}
	}
	return aWeapon.maxRange() < bWeapon.maxRange();
}